import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;

public class JailUI extends JPanel {
	private BoardUi board;
	private JButton btnReturn, btnPay;
	private Player p;
	private int inJailPayment = 50;
	
	public JailUI(Player currentPlayer, InJail inJail, BoardUi board_ ) {
		this.board = board_;
		this.p = currentPlayer;
		
		setBackground(new Color(240, 255, 255));
		
		setLayout(null);
		btnReturn = new JButton("Return");
		btnReturn.setFont(new Font("Verdana", Font.PLAIN, 12));
		btnReturn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				returnGame();
			}
		});
		btnReturn.setBounds(198, 88, 82, 23);
		add(btnReturn);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon(JailUI.class.getResource("/TitleDeeds/InJailUi.jpg")));
		label.setBounds(0, 0, 200, 200);
		add(label);
		
		btnPay = new JButton("Pay");
		btnPay.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				pay();
			}
		});
		btnPay.setBounds(198, 54, 82, 23);
		add(btnPay);
	}
	
	public void pay(){
		if(board.getCurrentPlayer().getInJail()==true){
			
		if(board.getCurrentPlayer().getMoney()>= inJailPayment){
		p.subtractMoney(inJailPayment);
		board.setCurrentPlayer();
		board.getPlayerPanelUI().updatePlayerMoney();
		board.MoveOutOfJail();
		btnPay.setEnabled(false);	//you can pay one time per turn
		board.getGameButtonUI().enableEndTurnBtn();
		JOptionPane.showMessageDialog(null,"You can press Susunod!");
		setVisible(false);
		board.getDiceUI().disableRollBtn();
		}else{
			board.getCurrentPlayer().setActive(false);
			JOptionPane.showMessageDialog(null,"Sorry, You don't have enough Money to get Out!, Try Roll");
		}
		}else{
			JOptionPane.showMessageDialog(null,"No need to pay, you are out of Jail, Press Return");
		}
	}
	
	public void returnGame(){
		if(board.getCurrentPlayer().getInJail()==false){
			setVisible(false);
			board.getGameButtonUI().enableEndTurnBtn();	
		}else{
			JOptionPane.showMessageDialog(null,"Pay, or Roll Please!");
		}
	}
}
